<?php
/**
 * 我的商城
 *
 * @好商城 (c) 2015-2018 33HAO Inc. (http://www.33hao.com)
 * @license    http://www.33 hao.c om
 * @link       交流群号：138182377
 * @since      好商城提供技术支持 授权请购买shopnc授权
 */



defined('In33hao') or exit('Access Invalid!');

class member_promotionControl extends mobileMemberControl {

    public function __construct(){
        parent::__construct();
    }

    //我的推广首页
    public function indexOp(){
        $model_mb_user_token = Model('mb_user_token');
        $key = $_POST['key'];
        if(empty($key)) {
            $key = $_GET['key'];
        }
        $mb_user_token_info = $model_mb_user_token->getMbUserTokenInfoByToken($key);
        $member_mobel = Model("member");
        $member_info = $member_mobel->getMemberInfo(array("member_id"=>$mb_user_token_info['member_id']));
        $member_info['member_time'] = date("Y-m-d H:i:s",$member_info['member_time']);
        output_data($member_info);
    }

    /**
     * 分销管理
     */
    public function listOp(){
        $model_mb_user_token = Model('mb_user_token');
        $key = $_POST['key'];
        if(empty($key)) {
            $key = $_GET['key'];
        }
        $Lev = $_POST['Lev'];
        $mb_user_token_info = $model_mb_user_token->getMbUserTokenInfoByToken($key);
        $member_mobel = Model("member");
        $where['Lev1'] = $mb_user_token_info['member_id'];
        $promotionlist = array();
        if($Lev==3){
             $where['Lev3'] = array("neq",'');
             $promotionlist = $member_mobel->getMemberList($where);
        }
        if($Lev==2){
            $where['Lev2'] = array("neq",'');
            $promotionlist = $member_mobel->getMemberList($where);
        }else{
            $promotionlist = $member_mobel->getMemberList($where);
        }

        output_data(array('promotion_info' => $promotionlist));
    }

    // 分销详情
    public function promotion_detailsOp(){
                $member_id = $_POST['mid'];
                $borkerage = 0;
                $order_list = '';
                $borkeragelist = Model("pd_log")->where(array("lg_member_id"=>$member_id))->select();
                if(!empty($borkeragelist)){
                    foreach($borkeragelist as $k => $value){
                        $orderNum = explode(':',$value['lg_desc']);
                        $borkeragelist[$k]['orderList'] = Model('order')->getOrderInfo(array("order_sn"=>$orderNum[1]),array('order_goods'));
                        $borkerage+= intval($value['lg_av_brokerage']);
                    }
                }
                $promotionlist['orderNum'] = Model("pd_log")->where(array("lg_member_id"=>$member_id))->count();
                $promotionlist['brokerageTotal'] = $borkerage;
                $promotionlist['orderList'] = $borkeragelist;
                output_data(array('promotion_details' => $promotionlist));
    }

    /**
     * 我的资产
     */
    public function my_brokeragesOp() {
        $param = $_GET;
        $fields_arr = array('point','predepoit','available_rc_balance','redpacket','voucher','brokerage');
        $fields_str = trim($param['fields']);
        if ($fields_str) {
            $fields_arr = explode(',',$fields_str);
        }
        $member_info = array();
        if (in_array('point',$fields_arr)) {
            $member_info['point'] = $this->member_info['member_points'];
        }
        if (in_array('predepoit',$fields_arr)) {
            $member_info['predepoit'] = $this->member_info['available_predeposit'];
        }
        if (in_array('available_rc_balance',$fields_arr)) {
            $member_info['available_rc_balance'] = $this->member_info['available_rc_balance'];
        }
        if (in_array('brokerage',$fields_arr)) {
            $member_info['brokerage'] = $this->member_info['brokerage'];
        }
        if (in_array('redpacket',$fields_arr)) {
            $member_info['redpacket'] = Model('redpacket')->getCurrentAvailableRedpacketCount($this->member_info['member_id']);
        }
        if (in_array('voucher',$fields_arr)) {
            $member_info['voucher'] = Model('voucher')->getCurrentAvailableVoucherCount($this->member_info['member_id']);
        }
        output_data($member_info);
    }

    /**
     * 分销订单
     */
    function distributio_orderOp(){
        $model_mb_user_token = Model('mb_user_token');
        $key = $_POST['key'];
        if(empty($key)) {
            $key = $_GET['key'];
        }
        $mb_user_token_info = $model_mb_user_token->getMbUserTokenInfoByToken($key);
        $member_mobel = Model("member");
        $where['Lev1'] = $mb_user_token_info['member_id'];
        $data_list =  $member_mobel->getMemberList($where);
        $idArr = [];
        foreach($data_list as $v){

        }
    }

    /**
     * 佣金日志列表
     */
    public function brokeragelogOp(){
        $model_predeposit = Model('predeposit');
        $where = array();
        $where['lg_inviter'] = $this->member_info['member_id'];
        $where['lg_av_amount'] = array('neq',0);
        $list = $model_predeposit->getPdLogList($where, $this->page, '*', 'lg_id desc');
        $page_count = $model_predeposit->gettotalpage();
        if ($list) {
            foreach($list as $k=>$v){
                $v['lg_add_time_text'] = @date('Y-m-d H:i:s',$v['lg_add_time']);
                $list[$k] = $v;
            }
        }
        output_data(array('list' => $list), mobile_page($page_count));
    }
}
